<?php
include './common/page.class.php';
include './common/smarty.php';

include_once '../business/market_manager.php';

$marketMng    = new MarketMng();

define('PAGESIZE',10);
define('LISTPAGE',5);
$sortField      = "id";
$sortDirection  = "";
$page           = $_GET['page']?$_GET["page"]:1;
$start          = ( $page-1)*PAGESIZE;

//get all markets page by page;
$marketList     = $marketMng->getAll($start, PAGESIZE, $sortField, $sortDirection);

//Pagesize = -1 just to get the items' num.
$marketNum      = $marketMng->getAll($start, -1, $sortField, $sortDirection);
$itemNums       = $marketNum[0][count];

//use page.php class  to create pages;
$pager = new listPage($itemNums,PAGESIZE,LISTPAGE);
$pager->firstPage   = 'First';
$pager->cssClass    = 'FONT3';
$pager->lastPage    = 'Previous';
$pager->nextPage    = 'Next';
$pager->splitStr    = '&nbsp;&nbsp;&nbsp;&nbsp;';
$pager->createPage();

//To assign values to Smarty template;
$tpl->assign("List2",       $marketList);
$tpl->assign("pager",       $pager);
$tpl->assign("page",        $page);
$tpl->assign("mngPage",     "marketMng.php");

//To display with tempplate
$tpl->display("../templates/marketList.html");
?>